package com.colabo.j2ee.web.core.vo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Used for caching the data used in backend of the application
 * @author Anthony Do
 * @since 2009-12-23
 *
 */
public class ApplicationData {
	private static ApplicationData APPLICATION_DATA = null;
	
	/**
	 * Singleton pattern for retrieve the application cache
	 * @return AppicationData instance
	 */
	public static ApplicationData getInstance() {
		if (APPLICATION_DATA == null) {
			APPLICATION_DATA = new ApplicationData();
		}
		return APPLICATION_DATA;
	}

	private ApplicationData() {
	}
	
	/**
	 * file path for the configuration files
	 */
	private String configurationFilePath;
	
	/**
	 * frontend error page url
	 */
	private String errorPageURL;
	
	/**
	 * store the dictionaries
	 */
	private Map<String, List> dictionaries = null;
	
	/**
	 * Retrieve the dictionary with the given dictionary name
	 * @param dicName
	 * 				- name of the dictionary
	 * @return dictionary, a list of items,  or an empty dictionary
	 */
	public List getDictionary(String dicName) {
		if (dicName == null || dicName.equals("")) {
			return new ArrayList();
		}
		Object obj = dictionaries.get(dicName);
		return obj != null ? (List) obj : new ArrayList();
	}

	public String getConfigurationFilePath() {
		return configurationFilePath;
	}

	public void setConfigurationFilePath(String configurationFilePath) {
		this.configurationFilePath = configurationFilePath;
	}

	public String getErrorPageURL() {
		return errorPageURL;
	}

	public void setErrorPageURL(String errorPageURL) {
		this.errorPageURL = errorPageURL;
	}

	public Map<String, List> getDictionaries() {
		return dictionaries;
	}

	public void setDictionaries(Map<String, List> dictionaries) {
		this.dictionaries = dictionaries;
	}
}
